/**
 * ************************************************************************
 *
 * @file    RingBuffer.h
 * @brief   简易环形数组
 * @author  负号科技(fuhaokj@foxmail.com)
 * @version 0.1
 * @date    2023-06-07
 *
 * ************************************************************************
 *   __       _                 _    _
 *  / _|     | |               | |  (_)
 * | |_ _   _| |__   __ _  ___ | | ___
 * |  _| | | | '_ \ / _` |/ _ \| |/ / |
 * | | | |_| | | | | (_| | (_) |   <| |
 * |_|  \__,_|_| |_|\__,_|\___/|_|\_\ |
 *                                 _/ |
 *                                |__/
 *
 * @copyright Copyright (c) 2023 负号科技
 * For study and research only, no reprinting
 * ************************************************************************
 */

#ifndef _RINGBUFFER_H_
#define _RINGBUFFER_H_

#include <stdint.h>

#define BUFFER_MAX 39 // TFT串口缓冲区大小

#define RingBuffer_Buffer(Buffer_Name,Buffer_Byte) \
    struct RingBuffer_t                \
    {                                  \
        uint8_t HeadPostion;           \
        uint8_t TailPostion;           \
        uint8_t Length;                \
        uint8_t Buffer[Buffer_Byte];    \
    }Buffer_Name

typedef void (*analysis)(uint8_t *Dat, uint8_t tempdata);
typedef struct RingBuffer_t RingBuffer;
struct RingBuffer_t
{
    uint8_t HeadPostion;        // 缓冲区头部位置
    uint8_t TailPostion;        // 缓冲区尾部位置
    uint8_t Length;             // 缓冲区长度
    uint8_t Buffer[BUFFER_MAX]; // 缓冲区数组
};

// extern RingBuffer TFTRX_RingBuffer;

void RingBuffer_Init(RingBuffer *FIFO);
uint8_t Read_RingBuffer(RingBuffer *FIFO, uint8_t *Dat);
uint8_t TFT_RX_ISR(RingBuffer *FIFO, uint8_t recdata);

#endif
